package com.Jhu1.mapper;

import com.Jhu1.entity.Store;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MerchantMapper {
    @Select("""
            select * from store
            """)
    List<Store> getMerchantAll();
    
    @Select("""
            select * from store
            where store_name = #{storeName}
            """)
    Store getMerchantByName(String storeName);
    
    @Insert("""
            insert into store(store_name, store_address,store_category, create_time, update_time)
            values(#{storeName},#{storeAddress},#{storeCategory},now(),now())
            """)
    void add(Store merchant);
    
    @Delete("""
            delete from store
            where id = #{id}
            """)
    void delete(Integer id);
    
    @Select("""
            select id from store
            where merchant_id=#{merchantId}
            """)
    Integer selectByMerchantId(Integer merchantId);
    
    @Select("""
            select * from store
            where merchant_id=#{id}
            """)
    Store myStore(Integer id);
    
    @Update("""
            update store
            set store_name=#{store.storeName},store_address=#{store.storeAddress},store_category=#{store.storeCategory},update_time=now()
            where merchant_id=#{id}
            """)
    void update(Integer id, Store store);
    
    @Update("""
            update store
            set merchant_id=#{userId}
            where id=#{id}
            """)
    void register(Integer userId, Integer id);
}
